home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / perl5 / Glib / KeyFile.pod < prev    next >
Encoding:
Text File  |  2007-03-05  |  11.7 KB  |  755 lines

  1. =head1 NAME
  2.  
  3. Glib::KeyFile -  Parser for .ini-like files
  4.  
  5. =for position SYNOPSIS
  6.  
  7. =head1 SYNOPSIS
  8.  
  9.   use Glib;
  10.  
  11.   $data .= $_ while (<DATA>);
  12.  
  13.   $f = Glib::KeyFile->new;
  14.   $f->load_from_data($data);
  15.   if ($f->has_group('Main') && $f->has_key('Main', 'someotherkey')) {
  16.       $val = $f->get_integer('Main', 'someotherkey');
  17.       print $val . "\n";
  18.   }
  19.   0;
  20.   __DATA__
  21.   # a comment
  22.   [MainSection]
  23.   somekey=somevalue
  24.   someotherkey=42
  25.   someboolkey=true
  26.   listkey=1;1;2;3;5;8;13;21
  27.   localekey=Good Morning
  28.   localekey[it]=Buon giorno
  29.   localekey[es]=Buenas dias
  30.   localekey[fr]=Bonjour
  31.  
  32. =for position DESCRIPTION
  33.  
  34. =head1 DESCRIPTION
  35.  
  36. B<Glib::KeyFile> lets you parse, edit or create files containing groups of
  37. key-value pairs, which we call key files for lack of a better name. Several
  38. freedesktop.org specifications use key files now, e.g the Desktop Entry
  39. Specification and the Icon Theme Specification.
  40.  
  41. The syntax of key files is described in detail in the Desktop Entry
  42. Specification, here is a quick summary: Key files consists of groups of
  43. key-value pairs, interspersed with comments.
  44.  
  45. =cut
  46.  
  47.  
  48.  
  49. =for object Glib::KeyFile Parser for .ini-like files
  50. =cut
  51.  
  52.  
  53.  
  54.  
  55. =head1 METHODS
  56.  
  57. =head2 keyfile = Glib::KeyFile-E<gt>B<new> 
  58.  
  59. =over
  60.  
  61. =back
  62.  
  63. =head2 boolean = $key_file->B<get_boolean> ($group_name, $key)
  64.  
  65. =over
  66.  
  67. =over
  68.  
  69. =item * $group_name (string) 
  70.  
  71. =item * $key (string) 
  72.  
  73. =back
  74.  
  75. Retrieves a boolean value from $key inside $group_name.
  76.  
  77. May croak with a L<Glib::Error> in $@ on failure.
  78.  
  79. =back
  80.  
  81. =head2 list = $key_file->B<get_boolean_list> ($group_name, $key)
  82.  
  83. =over
  84.  
  85. =over
  86.  
  87. =item * $group_name (string) 
  88.  
  89. =item * $key (string) 
  90.  
  91. =back
  92.  
  93. Retrieves a list of booleans from $key inside $group_name.
  94.  
  95. May croak with a L<Glib::Error> in $@ on failure.
  96.  
  97. =back
  98.  
  99. =head2 $key_file-E<gt>B<set_boolean_list> ($group_name, $key, ...)
  100.  
  101. =over
  102.  
  103. =over
  104.  
  105. =item * $group_name (string) 
  106.  
  107. =item * $key (string) 
  108.  
  109. =item * ... (list) list of booleans
  110.  
  111. =back
  112.  
  113. Sets a list of booleans in $key inside $group_name.  If $key cannot be found
  114. then it is created.  If $group_name cannot be found then it is created.
  115.  
  116. =back
  117.  
  118. =head2 $key_file-E<gt>B<set_boolean> ($group_name, $key, $value)
  119.  
  120. =over
  121.  
  122. =over
  123.  
  124. =item * $group_name (string) 
  125.  
  126. =item * $key (string) 
  127.  
  128. =item * $value (boolean) 
  129.  
  130. =back
  131.  
  132. Sets a boolean value to $key inside $group_name.
  133. If $key is not found, it is created.
  134.  
  135. =back
  136.  
  137. =head2 string = $key_file-E<gt>B<get_comment> ($group_name=undef, $key=undef)
  138.  
  139. =over
  140.  
  141. =over
  142.  
  143. =item * $group_name (string or undef) 
  144.  
  145. =item * $key (string or undef) 
  146.  
  147. =back
  148.  
  149. Retreives a comment above $key from $group_name.  If $key is undef then
  150. $comment will be read from above $group_name.  If both $key and $group_name
  151. are undef, then $comment will be read from above the first group in the file.
  152.  
  153. May croak with a L<Glib::Error> in $@ on failure.
  154.  
  155. =back
  156.  
  157. =head2 $key_file-E<gt>B<set_comment> ($group_name, $key, $comment)
  158.  
  159. =over
  160.  
  161. =over
  162.  
  163. =item * $group_name (string or undef) 
  164.  
  165. =item * $key (string or undef) 
  166.  
  167. =item * $comment (string) 
  168.  
  169. =back
  170.  
  171. Places a comment above $key from $group_name.  If $key is undef then $comment
  172. will be written above $group_name.  If both $key and $group_name are undef,
  173. then $comment will be written above the first group in the file.
  174.  
  175. May croak with a L<Glib::Error> in $@ on failure.
  176.  
  177. =back
  178.  
  179. =head2 double = $key_file-E<gt>B<get_double> ($group_name, $key)
  180.  
  181. =over
  182.  
  183. =over
  184.  
  185. =item * $group_name (string) 
  186.  
  187. =item * $key (string) 
  188.  
  189. =back
  190.  
  191. Retrieves a double value from $key inside $group_name.
  192.  
  193. May croak with a L<Glib::Error> in $@ on failure.
  194.  
  195. =back
  196.  
  197. =head2 list = $key_file->B<get_double_list> ($group_name, $key)
  198.  
  199. =over
  200.  
  201. =over
  202.  
  203. =item * $group_name (string) 
  204.  
  205. =item * $key (string) 
  206.  
  207. =back
  208.  
  209. Retrieves a list of doubles from $key inside $group_name.
  210.  
  211. May croak with a L<Glib::Error> in $@ on failure.
  212.  
  213. =back
  214.  
  215. =head2 $key_file-E<gt>B<set_double_list> ($group_name, $key, ...)
  216.  
  217. =over
  218.  
  219. =over
  220.  
  221. =item * $group_name (string) 
  222.  
  223. =item * $key (string) 
  224.  
  225. =item * ... (list) list of doubles
  226.  
  227. =back
  228.  
  229. Sets a list of doubles in $key inside $group_name.  If $key cannot be found
  230. then it is created.  If $group_name cannot be found then it is created.
  231.  
  232. =back
  233.  
  234. =head2 $key_file-E<gt>B<set_double> ($group_name, $key, $value)
  235.  
  236. =over
  237.  
  238. =over
  239.  
  240. =item * $group_name (string) 
  241.  
  242. =item * $key (string) 
  243.  
  244. =item * $value (double) 
  245.  
  246. =back
  247.  
  248. Sets a double value to $key inside $group_name.
  249. If $key is not found, it is created.
  250.  
  251. =back
  252.  
  253. =head2 list = $key_file->B<get_groups>
  254.  
  255. =over
  256.  
  257. Returns the list of groups inside the key_file.
  258.  
  259. =back
  260.  
  261. =head2 boolean = $key_file-E<gt>B<has_group> ($group_name)
  262.  
  263. =over
  264.  
  265. =over
  266.  
  267. =item * $group_name (string) 
  268.  
  269. =back
  270.  
  271. Checks whether $group_name is present in $key_file.
  272.  
  273. =back
  274.  
  275. =head2 boolean = $key_file-E<gt>B<has_key> ($group_name, $key)
  276.  
  277. =over
  278.  
  279. =over
  280.  
  281. =item * $group_name (string) 
  282.  
  283. =item * $key (string) 
  284.  
  285. =back
  286.  
  287. Checks whether $group_name has $key in it.
  288.  
  289. May croak with a L<Glib::Error> in $@ on failure.
  290.  
  291. =back
  292.  
  293. =head2 integer = $key_file->B<get_integer> ($group_name, $key)
  294.  
  295. =over
  296.  
  297. =over
  298.  
  299. =item * $group_name (string) 
  300.  
  301. =item * $key (string) 
  302.  
  303. =back
  304.  
  305. Retrieves an integer value from $key inside $group_name.
  306.  
  307. May croak with a L<Glib::Error> in $@ on failure.
  308.  
  309. =back
  310.  
  311. =head2 list = $key_file->B<get_integer_list> ($group_name, $key)
  312.  
  313. =over
  314.  
  315. =over
  316.  
  317. =item * $group_name (string) 
  318.  
  319. =item * $key (string) 
  320.  
  321. =back
  322.  
  323. Retrieves a list of integers from $key inside $group_name.
  324.  
  325. May croak with a L<Glib::Error> in $@ on failure.
  326.  
  327. =back
  328.  
  329. =head2 $key_file-E<gt>B<set_integer_list> ($group_name, $key, ...)
  330.  
  331. =over
  332.  
  333. =over
  334.  
  335. =item * $group_name (string) 
  336.  
  337. =item * $key (string) 
  338.  
  339. =item * ... (list) list of integers
  340.  
  341. =back
  342.  
  343. Sets a list of doubles in $key inside $group_name.  If $key cannot be found
  344. then it is created.  If $group_name cannot be found then it is created.
  345.  
  346. =back
  347.  
  348. =head2 $key_file-E<gt>B<set_integer> ($group_name, $key, $value)
  349.  
  350. =over
  351.  
  352. =over
  353.  
  354. =item * $group_name (string) 
  355.  
  356. =item * $key (string) 
  357.  
  358. =item * $value (integer) 
  359.  
  360. =back
  361.  
  362. Sets an integer value to $key inside $group_name.
  363. If $key is not found, it is created.
  364.  
  365. =back
  366.  
  367. =head2 list = $key_file->B<get_keys> ($group_name)
  368.  
  369. =over
  370.  
  371. =over
  372.  
  373. =item * $group_name (string) 
  374.  
  375. =back
  376.  
  377. Returns the list of keys inside a group of the key file.
  378.  
  379. May croak with a L<Glib::Error> in $@ on failure.
  380.  
  381. =back
  382.  
  383. =head2 $key_file-E<gt>B<set_list_separator> ($separator)
  384.  
  385. =over
  386.  
  387. =over
  388.  
  389. =item * $separator (string) 
  390.  
  391. =back
  392.  
  393. Sets the list separator character.
  394.  
  395. =back
  396.  
  397. =head2 boolean = $key_file-E<gt>B<load_from_data> ($buf, $flags)
  398.  
  399. =over
  400.  
  401. =over
  402.  
  403. =item * $buf (scalar) 
  404.  
  405. =item * $flags (Glib::KeyFileFlags) 
  406.  
  407. =back
  408.  
  409. Parses a string containing a key file structure.
  410.  
  411. May croak with a L<Glib::Error> in $@ on failure.
  412.  
  413. =back
  414.  
  415. =head2 boolean = $key_file->B<load_from_data_dirs> ($file, $flags)
  416.  
  417. =head2 (boolean, scalar) = $key_file->B<load_from_data_dirs> ($file, $flags)
  418.  
  419. =over
  420.  
  421. =over
  422.  
  423. =item * $file (string) 
  424.  
  425. =item * $flags (Glib::KeyFileFlags) 
  426.  
  427. =back
  428.  
  429.  
  430. Parses a key file, searching for it inside the data directories.
  431. In scalar context, it returns a boolean value (true on success, false otherwise);
  432. in array context, it returns a boolean value and the full path of the file.
  433.  
  434. May croak with a L<Glib::Error> in $@ on failure.
  435.  
  436. =back
  437.  
  438. =head2 boolean = $key_file-E<gt>B<load_from_file> ($file, $flags)
  439.  
  440. =over
  441.  
  442. =over
  443.  
  444. =item * $file (string) 
  445.  
  446. =item * $flags (Glib::KeyFileFlags) 
  447.  
  448. =back
  449.  
  450. Parses a key file.
  451.  
  452. May croak with a L<Glib::Error> in $@ on failure.
  453.  
  454. =back
  455.  
  456. =head2 string = $key_file-E<gt>B<get_locale_string> ($group_name, $key, $locale=undef)
  457.  
  458. =over
  459.  
  460. =over
  461.  
  462. =item * $group_name (string) 
  463.  
  464. =item * $key (string) 
  465.  
  466. =item * $locale (string or undef) 
  467.  
  468. =back
  469.  
  470. Returns the value associated with $key under $group_name translated in the
  471. given $locale if available.  If $locale is undef then the current locale is
  472. assumed.
  473.  
  474. May croak with a L<Glib::Error> in $@ on failure.
  475.  
  476. =back
  477.  
  478. =head2 list = $key_file-E<gt>B<get_locale_string_list> ($group_name, $key, $locale)
  479.  
  480. =over
  481.  
  482. =over
  483.  
  484. =item * $group_name (string) 
  485.  
  486. =item * $key (string) 
  487.  
  488. =item * $locale (string) 
  489.  
  490. =back
  491.  
  492.  
  493.  
  494. May croak with a L<Glib::Error> in $@ on failure.
  495.  
  496. =back
  497.  
  498. =head2 $key_file-E<gt>B<set_locale_string_list> ($group_name, $key, $locale, ...)
  499.  
  500. =over
  501.  
  502. =over
  503.  
  504. =item * $group_name (string) 
  505.  
  506. =item * $key (string) 
  507.  
  508. =item * $locale (string) 
  509.  
  510. =item * ... (list) 
  511.  
  512. =back
  513.  
  514. Associates a list of string values for $key and $locale under $group_name.
  515. If the translation for $key cannot be found then it is created.
  516.  
  517. =back
  518.  
  519. =head2 $key_file-E<gt>B<set_locale_string> ($group_name, $key, $locale, $string)
  520.  
  521. =over
  522.  
  523. =over
  524.  
  525. =item * $group_name (string) 
  526.  
  527. =item * $key (string) 
  528.  
  529. =item * $locale (string) 
  530.  
  531. =item * $string (string) 
  532.  
  533. =back
  534.  
  535. =back
  536.  
  537. =head2 $key_file-E<gt>B<remove_comment> ($group_name=undef, $key=undef)
  538.  
  539. =over
  540.  
  541. =over
  542.  
  543. =item * $group_name (string or undef) 
  544.  
  545. =item * $key (string or undef) 
  546.  
  547. =back
  548.  
  549. Removes a comment from a group in a key file.  If $key is undef, the comment
  550. will be removed from above $group_name.  If both $key and $group_name are
  551. undef, the comment will be removed from the top of the key file.
  552.  
  553. May croak with a L<Glib::Error> in $@ on failure.
  554.  
  555. =back
  556.  
  557. =head2 $key_file-E<gt>B<remove_group> ($group_name)
  558.  
  559. =over
  560.  
  561. =over
  562.  
  563. =item * $group_name (string) 
  564.  
  565. =back
  566.  
  567. Removes a group from a key file.
  568.  
  569. May croak with a L<Glib::Error> in $@ on failure.
  570.  
  571. =back
  572.  
  573. =head2 $key_file-E<gt>B<remove_key> ($group_name, $key)
  574.  
  575. =over
  576.  
  577. =over
  578.  
  579. =item * $group_name (string) 
  580.  
  581. =item * $key (string) 
  582.  
  583. =back
  584.  
  585. Removes a key from $group_name.
  586.  
  587. May croak with a L<Glib::Error> in $@ on failure.
  588.  
  589. =back
  590.  
  591. =head2 string = $key_file-E<gt>B<get_start_group> 
  592.  
  593. =over
  594.  
  595. Returns the first group inside a key file.
  596.  
  597. =back
  598.  
  599. =head2 string = $key_file->B<get_string> ($group_name, $key)
  600.  
  601. =over
  602.  
  603. =over
  604.  
  605. =item * $group_name (string) 
  606.  
  607. =item * $key (string) 
  608.  
  609. =back
  610.  
  611. Retrieves a string value from $key inside $group_name.
  612.  
  613. May croak with a L<Glib::Error> in $@ on failure.
  614.  
  615. =back
  616.  
  617. =head2 list = $key_file->B<get_string_list> ($group_name, $key)
  618.  
  619. =over
  620.  
  621. =over
  622.  
  623. =item * $group_name (string) 
  624.  
  625. =item * $key (string) 
  626.  
  627. =back
  628.  
  629. Retrieves a list of strings from $key inside $group_name.
  630.  
  631. May croak with a L<Glib::Error> in $@ on failure.
  632.  
  633. =back
  634.  
  635. =head2 $key_file-E<gt>B<set_string_list> ($group_name, $key, ...)
  636.  
  637. =over
  638.  
  639. =over
  640.  
  641. =item * $group_name (string) 
  642.  
  643. =item * $key (string) 
  644.  
  645. =item * ... (list) list of strings
  646.  
  647. =back
  648.  
  649. Sets a list of strings in $key inside $group_name.  The strings will be escaped
  650. if contain special characters.  If $key cannot be found then it is created.  If
  651. $group_name cannot be found then it is created.
  652.  
  653. =back
  654.  
  655. =head2 $key_file-E<gt>B<set_string> ($group_name, $key, $value)
  656.  
  657. =over
  658.  
  659. =over
  660.  
  661. =item * $group_name (string) 
  662.  
  663. =item * $key (string) 
  664.  
  665. =item * $value (string) 
  666.  
  667. =back
  668.  
  669. Sets a string value to $key inside $group_name.  The string will be escaped if
  670. it containes special characters.
  671. If $key is not found, it is created.
  672.  
  673. =back
  674.  
  675. =head2 string = $key_file-E<gt>B<to_data> 
  676.  
  677. =over
  678.  
  679. Returns the key file as a string.
  680.  
  681. May croak with a L<Glib::Error> in $@ on failure.
  682.  
  683. =back
  684.  
  685. =head2 string = $key_file-E<gt>B<get_value> ($group_name, $key)
  686.  
  687. =over
  688.  
  689. =over
  690.  
  691. =item * $group_name (string) 
  692.  
  693. =item * $key (string) 
  694.  
  695. =back
  696.  
  697. Retrieves the literal value of $key inside $group_name.
  698.  
  699. May croak with a L<Glib::Error> in $@ on failure.
  700.  
  701. =back
  702.  
  703. =head2 $key_file-E<gt>B<set_value> ($group_name, $key, $value)
  704.  
  705. =over
  706.  
  707. =over
  708.  
  709. =item * $group_name (string) 
  710.  
  711. =item * $key (string) 
  712.  
  713. =item * $value (string) 
  714.  
  715. =back
  716.  
  717. Sets the literal value of $key inside $group_name.
  718. If $key cannot be found, it is created.
  719. If $group_name cannot be found, it is created.
  720.  
  721. =back
  722.  
  723.  
  724. =head1 ENUMS AND FLAGS
  725.  
  726. =head2 flags Glib::KeyFileFlags
  727.  
  728.  
  729.  
  730. =over
  731.  
  732. =item * 'none' / 'G_KEY_FILE_NONE'
  733.  
  734. =item * 'keep-comments' / 'G_KEY_FILE_KEEP_COMMENTS'
  735.  
  736. =item * 'keep-translations' / 'G_KEY_FILE_KEEP_TRANSLATIONS'
  737.  
  738. =back
  739.  
  740.  
  741.  
  742. =head1 SEE ALSO
  743.  
  744. L<Glib>
  745.  
  746. =head1 COPYRIGHT
  747.  
  748. Copyright (C) 2003-2006 by the gtk2-perl team.
  749.  
  750. This software is licensed under the LGPL.  See L<Glib> for a full notice.
  751.  
  752.  
  753. =cut
  754.  
  755.